package com.csi.service.impl;

import com.csi.dao.HistoryDao;
import com.csi.dao.impl.HistoryDaoImpl;
import com.csi.domain.History;
import com.csi.pojo.PageBean;
import com.csi.service.HistoryService;

import java.sql.SQLException;
import java.util.*;

public class HistoryServiceImpl implements HistoryService {
    @Override
    public void add(History history) {
        HistoryDao historyDao = new HistoryDaoImpl();

        try {
            historyDao.add(history);
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
    }

    @Override
    public Double queryTodayAmount(String userNumber) {
        HistoryDao historyDao = new HistoryDaoImpl();

        Double todayAmount = null;
        try {
            todayAmount = historyDao.queryTodayAmount(userNumber);
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }

        return todayAmount;
    }

    @Override
    public List<History> queryAll(String userNumber) {
        HistoryDao historyDao = new HistoryDaoImpl();

        List<History> histories = null;
        try {
            histories = historyDao.queryAll(userNumber);
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }

        return histories;
    }

    @Override
    public List<History> queryByType(String userNumber, String operationType) {
        HistoryDao historyDao = new HistoryDaoImpl();

        List<History> histories = null;
        try {
            histories = historyDao.queryByType(userNumber, operationType);
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }

        return histories;
    }

    @Override
    public PageBean findPageByTime(Date date, int currentPageNumber) {
        HistoryDao historyDao = new HistoryDaoImpl();

        PageBean pageBean = null;
        try {
            pageBean = historyDao.findPageByTime(date, currentPageNumber);
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }

        return pageBean;
    }

    @Override
    public PageBean findPageAll(int currentPageNumber) {
        HistoryDao historyDao = new HistoryDaoImpl();

        PageBean pageBean = null;
        try {
            pageBean = historyDao.findPageAll(currentPageNumber);
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }

        return pageBean;
    }

    @Override
    public PageBean findPageByUserNumber(int currentPageNumber, String userNumber) {
        HistoryDao historyDao = new HistoryDaoImpl();

        PageBean pageBean = null;
        try {
            pageBean = historyDao.findPageByUserNumber(currentPageNumber, userNumber);
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }

        return pageBean;
    }

    @Override
    public List<String> findAllUserNumber() {
        HistoryDao historyDao = new HistoryDaoImpl();

        List<String> list = null;
        try {
            list = historyDao.findAllUserNumber();
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }

        return list;
    }

    @Override
    public List<History> queryByMonth(String userNumber, int year, int month) {
        HistoryDao historyDao = new HistoryDaoImpl();

        List<History> histories = null;
        try {
            histories = historyDao.queryByMonth(userNumber, year, month);
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }

        return histories;
    }

    @Override
    public PageBean findPageByType(int currentPageNumber, String userNumber, String operationType) {
        HistoryDao historyDao = new HistoryDaoImpl();

        PageBean pageBean = null;
        try {
            pageBean = historyDao.findPageByType(currentPageNumber, userNumber, operationType);
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }

        return pageBean;
    }

    @Override
    public PageBean findAllPageByType(int currentPageNumber, String operationType) {
        HistoryDao historyDao = new HistoryDaoImpl();

        PageBean pageBean = null;
        try {
            pageBean = historyDao.findAllPageByType(currentPageNumber, operationType);
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }

        return pageBean;
    }

    @Override
    public Double findAmountByDate(Date date) {
        HistoryDao historyDao = new HistoryDaoImpl();

        Double totalAmount = null;
        try {
            totalAmount = historyDao.findAmountByDate(date);
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }

        return totalAmount;
    }

    @Override
    public Integer findNumberByDate(Date date) {
        HistoryDao historyDao = new HistoryDaoImpl();

        Integer number = null;
        try {
            number = historyDao.findNumberByDate(date);
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }

        return number;
    }

    @Override
    public Map<Date, Double> findAmountsByMonth(int year, int month) {
        HistoryDao historyDao = new HistoryDaoImpl();

        Map<Date, Double> map = null;
        try {
            map = historyDao.findAmountsByMonth(year, month);
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }

        return map;
    }

    @Override
    public Map<String, Integer> findNumbersByYear(int year) {
        HistoryDao historyDao = new HistoryDaoImpl();

        Map<String, Integer> map = null;
        try {
            map = historyDao.findNumbersByYear(year);
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }

        return map;
    }

}
